package gold.digger;

import gold.utils.InputUtil;

import java.util.*;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC1027 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int longestArithSeqLength(int[] nums) {
            int n = nums.length, ans = 0;
            int[][] dp = new int[n][1002];
            for (int i = 1; i < n; i++) {
                for (int j = 0; j < i; j++) {
                    int p = nums[i] - nums[j] + 500;
                    dp[i][p] = Math.max(dp[i][p], dp[j][p] + 1);
                    ans = Math.max(ans, dp[i][p]);
                }
            }

            return ans + 1;
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.longestArithSeqLength(InputUtil.toIntegerArray("[3,6,9,12]")));
        System.out.println(solution.longestArithSeqLength(InputUtil.toIntegerArray("[9,4,7,2,10]")));
        System.out.println(solution.longestArithSeqLength(InputUtil.toIntegerArray("[20,1,15,3,10,5,8]")));
    }

    public static void main(String[] args) throws Exception {
        LC1027 an = new LC1027();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
